module ExprPP where
import ExprDataTypes 
import ExprSyntax 
import ExprTokens 

formatter a = putStr (pp_bloque a 0)

pp_indent inum str = concat (replicate inum "\t" ++ [str])

pp_bloque (a:[]) inum = (pp_indent inum (pprint6 (fst a) inum)) ++ "\n"
pp_bloque (x:xs) inum = (pp_indent inum (pprint6 (fst x) inum)) ++ ";\n" ++ (pp_bloque xs inum)

pprint6 (Mas e1 e2) inum = pprint6 (fst e1) inum ++ " + " ++ pprint6 (fst e2) inum 
pprint6 (Menos e1 e2)  inum = pprint6 (fst e1) inum ++ " - " ++ pprint6 (fst e2) inum 
pprint6 (Por e1 e2)  inum = pprint6 (fst e1) inum ++ " * " ++ pprint6 (fst e2) inum 
pprint6 (Div e1 e2)  inum = pprint6 (fst e1) inum ++ " / " ++ pprint6 (fst e2) inum
pprint6 (Igual e1 e2)  inum = pprint6 (fst e1) inum ++ " = " ++ pprint6 (fst e2) inum
pprint6 (Distinto e1 e2)  inum = pprint6 (fst e1) inum ++ " <> " ++ pprint6 (fst e2) inum
pprint6 (Menor e1 e2)  inum = pprint6 (fst e1) inum ++ " < " ++ pprint6 (fst e2) inum
pprint6 (Mayor e1 e2)  inum = pprint6 (fst e1) inum ++ " > " ++ pprint6 (fst e2) inum
pprint6 (MayorIgual e1 e2)  inum = pprint6 (fst e1) inum ++ " >= " ++ pprint6 (fst e2) inum
pprint6 (MenorIgual e1 e2)  inum = pprint6 (fst e1) inum ++ " <= " ++ pprint6 (fst e2) inum
pprint6 (Parentesis e)  inum = " ( " ++ pprint6 (fst e) inum ++ " ) "
pprint6 (ONot e)  inum = " !" ++ pprint6 (fst e) inum 
pprint6 (OAnd e1 e2)  inum = pprint6 (fst e1) inum ++ " & " ++ pprint6 (fst e2) inum
pprint6 (OOr e1 e2)  inum = pprint6 (fst e1) inum ++ " | " ++ pprint6 (fst e2) inum
pprint6 BTrue  inum = " true " 
pprint6 BFalse  inum = " false "
pprint6 (Id a)  inum = a
pprint6 (NumInt n)  inum = show n
pprint6 (NumDouble n)  inum = show n
pprint6 (Asignacion a e)  inum = a ++ " := " ++ pprint6 (fst e) inum
pprint6 (Declaracion a1 a2 NoExp)  inum = a1 ++ " " ++ a2
pprint6 (Declaracion a1 a2 (EOpc c))  inum = a1 ++ " " ++ a2 ++ " := " ++ pprint6 (fst c)  inum
pprint6 (Secuencia e1 e2)  inum = pprint6 (fst e1) inum++ "; " ++ pprint6 (fst e2) inum 
pprint6 (Condicional e1 e2 NoBloque) inum = "if " ++ pprint6 (fst e1) inum ++ " then {\n" ++ pp_bloque e2 (inum +1) ++ "}"
pprint6 (Condicional e1 e2 (BElse b)) inum = "if " ++ pprint6 (fst e1) inum ++ " then {\n" ++ pp_bloque e2  (inum+1) ++ "} else {\n" ++ pp_bloque b (inum+1) ++ "}"
pprint6 (Iteracion e1 e2 (BElse e3)) inum =  "while " ++ pprint6 (fst e1) inum ++ " repeat {\n" ++ pp_bloque e2 (inum+1) ++ "} else {\n" ++ pp_bloque e3 (inum+1)++ "}\n"
pprint6 (Iteracion e1 e2 NoBloque) inum =  "while " ++ pprint6 (fst e1) inum ++ " repeat {\n" ++ pp_bloque e2  (inum+1) ++ "}"
pprint6 (Read) inum = "read " 
pprint6 (Write e) inum = "write " ++ e
pprint6 (Length e) inum = "length " ++ e
pprint6 (Lit a) inum =  a


